home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
games
/
tmloto13.zip
/
TIMELOTO.MEX
< prev
next >
Wrap
Text File
|
1996-10-30
|
16KB
|
460 lines
/////////////////////////////////////////////////////////////////////////////
// Normal rules apply,this is my copyrighted program etc //
// If you use and like the program please either netmail or email me at //
// the address' below.If you like to send some money,then let me know and //
// I'll give you my home address :) //
// //
// You may alter this program for YOUR OWN USE ONLY,you cannot alter it //
// and send it out in a modified form. //
// I'd welcome comments,bug reports,ideas or code to be added //
// You may reach me at : 2:253/35@fidonet //
// 240:360/45@mercury //
// 81:444/25@os2net //
// mark.taylor@zetnet.co.uk (Quickest) //
// mark@trythat.coracle.com //
/////////////////////////////////////////////////////////////////////////////
#include <max.mh>
#include <rand.mh>
#define VERSION " V1.3\n" // Version number
#define MAX_LINES 10 // Maximum number of lines,use the users screen length
#define RANDOM 49 // Maximum value of number to pick
#define BALLS 6 // Number of random numbers to pick per line
#define TRY 50 // Number of random numbers before one is picked
#define BET 2 // Number of minutes to gamble on each line
#define MATCHED_1 1 // Number of minutes given for 1 number matched per line
#define MATCHED_2 2 // Number of minutes given for 2 numbers matched per line
#define MATCHED_3 5 // Number of minutes given for 3 numbers matched per line
#define MATCHED_4 10 // Number of minutes given for 4 numbers matched per line
#define MATCHED_5 15 // Number of minutes given for 5 numbers matched per line
#define MATCHED_6 25 // Number of minutes given for 6 numbers matched per line
#define MAX_TIME 120 // Maxium of time allowed for each user to be added
int: minutes_won , // total minutes won,if any :)
winning_lines , // How many winning lines
number_of_bets ; // How many bets (lines)
long: start_mins ; // minutes left at start
string: blanks ; // Blank line
array [1..BALLS] of int: computer_balls ; // Array for chosen balls
array [1..BALLS] of int: user_balls ; // Array for user chosen lottery balls
// Prototypes
string centre(string: s1) ;
void cls() ;
void print_title() ;
void pick_numbers(array [1..BALLS] of int: balls) ;
int getrandom() ;
void sort_numbers(array[1..BALLS] of int: balls) ;
void get_user_numbers() ;
void get_number_of_trys() ;
void print_line(array[1..BALLS] of int: balls,int: x) ;
int check_for_match(int: ball_to_check) ;
void help() ;
void print_stats() ;
int main() ;
// Centre Output
string centre(string: s1)
{
string: s2;
int: i1;
s2:="\r";
for(i1:=1; i1<=(((term_width()-2)-strlen(s1))/2); i1:=i1+1)
{ s2:=s2+" "; }
s2:=s2+s1;
return s2;
}
// Clear Screen
void cls()
{
print("\x0c");
}
// Just print out title and advert etc..
void print_title()
{
cls() ;
print(COL_LCYAN) ;
print(centre("Lottery Time Gamble"+VERSION)) ;
print(centre("Written By Mark Taylor (c)\n")) ;
print(centre("TryThat SoftWare 1996\n")) ;
print(COL_WHITE"\n") ;
}
// computer picked numbers
void pick_numbers(array [1..BALLS] of int: balls)
{
int: i,x,test,number ;
print(AVATAR_GOTO,(char)10,(char)40,COL_WHITE " ") ;
print(AVATAR_GOTO,(char)10,(char)40,COL_WHITE "Picking Numbers ") ;
for(i := 1 ; i <= BALLS ; i := i+1)
{
balls[i] := 50 ; // Set ball to a number,that is false
test := FALSE ;
while(test = FALSE)
{
test := TRUE ;
number := getrandom() ; // Get a random ball
// Make sure no dupes
for(x := 1 ; x < BALLS+1 ; x := x+1)
if(balls[x] = number)
test := FALSE ;
}
balls[i] := number ;
}
sort_numbers(balls) ;
}
// get a random number and print spinning bar
int getrandom()
{
int: number,z ;
for(z := 0 ; z < TRY ; z := z+1)
{
number := (rand()%RANDOM)+1 ; // Get a random number
if(z/4 = 0)
print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "\\") ;
if(z/8 = 0)
print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "-") ;
if(z/12 = 0)
print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "/") ;
if(z/16 = 0)
print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "|") ;
}
print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE " ") ;
return number ;
}
// Put balls into order
void sort_numbers(array[1..BALLS] of int: balls)
{
// There may be a faster way to sort,but then again there are'nt many numbers
int: swtch,x,temp ;
swtch := TRUE ;
while(swtch = TRUE)
{
swtch := FALSE ;
for(x := 1; x < BALLS ; x := x+1)
if(balls[x] >balls[x+1])
{
temp := balls[x] ;
balls[x] := balls[x+1] ;
balls[x+1] := temp ;
swtch := TRUE ;
}
}
}
// get user numbers
void get_user_numbers()
{
int: number,swtch,x,i;
string: get_number,prompt;
print(AVATAR_GOTO,(char)10,(char)1,blanks) ;
// print line ready to display user numbers
print(AVATAR_GOTO,(char)10,(char)1,"Your Numbers - ") ;
for(i := 1 ; i < BALLS+1 ; i := i+1)
{
prompt := "Please enter a number between 1 and "+itostr(RANDOM)+",then press return ";
swtch := TRUE ;
user_balls[i] := 50 ; // set a dummy number
while(swtch = TRUE)
{
while(swtch = TRUE)
{
// Get a number between 1 & RANDOM (49)
print(AVATAR_GOTO,(char)5,(char)1,blanks) ; // Print a line of blanks
print(AVATAR_GOTO,(char)5,(char)1 ) ;
input_str(get_number, INPUT_WORD, 0, 2,prompt);
number := strtoi(get_number) ;
if(number < 1 OR number > RANDOM)
prompt := "You must enter a number between 1 and "+itostr(RANDOM)+" " ;
else
swtch := FALSE ;
}
// Make sure no dupes
for(x := 1 ; x < BALLS+1 ; x := x+1)
if(user_balls[x] = number)
{
swtch := TRUE ;
prompt := "Please pick a differnt a number " ;
}
// this is a good number,so use it
if(swtch = FALSE)
{
user_balls[i] := number ;
print(AVATAR_GOTO,(char)10,(char)(15+(i*3)),COL_YELLOW,number,COL_WHITE) ;
}
}
}
sort_numbers(user_balls) ; // put the balls in order
}
// get number of lines to bet on
void get_number_of_trys()
{
int: swtch ;
string: get_number,prompt ;
long: number ;
number := timeleft() / BET ; // Get users time left,and see how many bets
if(number > MAX_LINES) // available.
number := MAX_LINES ; // If more than max limit,set it to max limit
prompt := "You have "+ltostr(timeleft())+" minutes to play with.\n"+
"Enter how many bets you'd like,upto a maximum of "+
ltostr(number)+",\nand remember each bet is "+itostr(BET)+
" Minutes taken off of your time? ";
swtch := TRUE ;
while(swtch = TRUE)
{
print(AVATAR_GOTO,(char)5,(char)1,blanks) ; // Print a blank line
print(AVATAR_GOTO,(char)6,(char)1,blanks) ; // Print a blank line
print(AVATAR_GOTO,(char)7,(char)1,blanks) ; // Print a blank line
print(AVATAR_GOTO,(char)5,(char)1 ) ; // set ready for printing
input_str(get_number, INPUT_WORD, 0, 2,prompt);
number_of_bets := strtoi(get_number) ; // convert string to int
if(number_of_bets < 1 OR number_of_bets > number)
prompt := "You must enter a number between 1 and "+ltostr(number)+" ? " ;
else
swtch := FALSE ;
}
timeadjustsoft(-(number_of_bets * BET * 60) ) ; // take off bet from users time
print(AVATAR_GOTO,(char)5,(char)1,blanks) ; // Print a blank line
print(AVATAR_GOTO,(char)6,(char)1,blanks) ;
print(AVATAR_GOTO,(char)7,(char)1,blanks) ;
// print(AVATAR_GOTO,(char)6,(char)1 ) ;
// print("You have ",timeleft()," minutes left,after your bet of ",number_of_bets * BET," minutes.\n") ;
log("TBet "+itostr(number_of_bets * BET)+" minutes" ); // Log the bet to logfile
// return number ;
}
// print out each computer line,then check for any winning numbers
void print_line(array[1..BALLS] of int: balls,int: x)
{
int: y,matches ;
matches := 0 ;
// Print out results,pad with spaces to make neat
print(AVATAR_GOTO,(char)(11+x),(char)1,
COL_LRED,"Line ",strpadleft(itostr(x),2,' ')," : ",COL_WHITE) ;
for(y := 1 ; y < BALLS+1 ; y := y+1)
if(check_for_match(balls[y]) = TRUE)
{
print(COL_GREEN,strpadleft(itostr(balls[y]),4,' '),COL_WHITE) ;
matches := matches + 1 ;
}
else
print(strpadleft(itostr(balls[y]),4,' ')) ;
if(matches > 1)
winning_lines := winning_lines +1 ;
// print out results if any matches
if(matches = 1)
{
print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_1," Minute",COL_WHITE ) ;
minutes_won := minutes_won+MATCHED_1 ;
}
else if(matches = 2)
{
print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_2," Minutes",COL_WHITE ) ;
minutes_won := minutes_won+MATCHED_2 ;
}
else if(matches = 3)
{
print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_3," Minutes",COL_WHITE ) ;
minutes_won := minutes_won+MATCHED_3 ;
}
else if(matches = 4)
{
print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_4," Minutes",COL_WHITE ) ;
minutes_won := minutes_won+MATCHED_4 ;
}
else if(matches = 5)
{
print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_5," Minutes",COL_WHITE ) ;
minutes_won := minutes_won+MATCHED_5 ;
}
else if(matches = 6)
{
print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_6," Minutes",COL_WHITE ) ;
minutes_won := minutes_won+MATCHED_6 ;
}
else
print(AVATAR_GOTO,(char)(11+x),(char)40,"You Have Not Won Anything!" ) ;
}
//simple check routine
int check_for_match(int: ball_to_check)
{
int: x,swtch ;
swtch := FALSE ;
for(x := 1 ; x < BALLS+1 ; x := x+1)
if(user_balls[x] = ball_to_check)
swtch := TRUE ;
return swtch ;
}
// show a very simple help screen
void help()
{
// you should'nt need to touch this much,unless you choose differnt colours
// for the results etc,but it does use the defines for most things.
// and its only 1 screen long :)
char: x ;
print(AVATAR_GOTO,(char)5,(char)1,"Do you need instructions [y/N]" ) ;
x := getch() ;
if(x = 'Y' or x = 'y') // check if intructions needed
{}
else
return ; // if not then lets get back to business
print(AVATAR_GOTO,(char)5,(char)1 ) ;
print("The object of this game is to gain on-line time,you do this by playing ",
"\nthe lottery,with a slight difference,you are gambling your time for ",
"\ntoday,if you lose it all don't worry,you'll be back to normal tomorrow.",
"\n",
"\nYou pick ",BALLS," numbers within the range of 1 to ",RANDOM,
",and then decide how many",
"\nlines you want the computer to generate,each line costs you ",BET," minutes, ",
"\nand you can have a maximum of ",MAX_LINES," lines. ",
"\nYou can win time back for a match on 2 to ",BALLS," numbers,upto a maximum of ",
"\n",MAX_TIME," minutes.",
"\nWhen you get a matching number it will show up as green eg ",COL_GREEN,"10"
,COL_WHITE," and any ",
"\ntime won will show up as blue eg ",COL_LCYAN,"15",COL_WHITE,".",
"\n",
"\nThats about it really,if you have problems please,let the sysop know,so ",
"\nI can fix them quickly.",
"\n\nHave Fun. Mark Taylor.",
"\n\nPress A Key"
) ;
x := getch() ;
// Clear the screen from just below the title
for(x := 5 ; x < 23 ; x:= x+1)
print(AVATAR_GOTO,(char)x,(char)1,blanks ) ;
}
// Print out stats
void print_stats()
{
int: x ;
long: mins_left ; // work out correct mins left,for some reason my orginal
// way did'nt always come up with the right answer.
// no idea why not though,if anyone has please let me know
mins_left := (start_mins - (number_of_bets * BET)) + minutes_won ;
print_title() ;
print(COL_YELLOW,"\n",centre("S T A T I S T I C S\n")) ;
print(centre("~~~~~~~~~~~~~~~~~~~~~\n"),COL_WHITE) ;
if(minutes_won > MAX_TIME)
minutes_won := MAX_TIME ;
print("\n Number of minutes at the start - ",
strpadleft(itostr(start_mins),4,' ')) ;
print("\n Number of bets placed - ",
strpadleft(itostr(number_of_bets),4,' ')) ;
print("\n Total minutes bet - ",COL_LRED,
strpadleft(itostr( (number_of_bets * BET) ),4,' '),COL_WHITE) ;
print("\n Total of minutes won - ",COL_LGREEN,
strpadleft(itostr(minutes_won),4,' '),COL_WHITE) ;
// print("\n Number of minutes left - ",
// strpadleft(itostr(timeleft()),4,' ')) ;
print("\n Number of minutes left - ",
strpadleft(itostr(mins_left),4,' ')) ;
if(mins_left = start_mins)
print("\n\n You neither lost or won,but broke even!") ;
else if(mins_left > start_mins)
print("\n\n You ",COL_LGREEN,"gained",COL_WHITE,
" a total of ",COL_LGREEN,mins_left - start_mins,COL_WHITE," minutes.") ;
else
print("\n\n You ",COL_LRED,"lost",COL_WHITE,
" a total of ",COL_LRED,start_mins - mins_left,COL_WHITE," minutes.") ;
print("\n\n\n Please Press A Key") ;
x := getch() ;
}
// main loop
int main()
{
// it does seem as though the user comes off worse most times :)
// I expect this could be changed so there is a slight bias in favour of the user,
// but that would take all the fun out of it :)
int: x ;
time_check(FALSE) ;// STOP time checking
log("TStarting Lottery Time Gamble"); // Log the start to logfile
start_mins := timeleft() ; // get minutes left
srand(time()); // Seed random generator
blanks := strpad(blanks,term_width(),' ') ; // set a blank line to users screen width
minutes_won := 0 ; // set winnings to zero
winning_lines := 0 ; // set winning line to zero
print_title() ; // print title
help() ; // check if instructions needed
get_user_numbers() ; // Get user numbers
get_number_of_trys() ; // get number of lines
// go through each line bet
for(x:= 1 ; x < number_of_bets+1 ; x := x+1)
{
pick_numbers(computer_balls) ;
print_line(computer_balls,x) ;
}
timeadjustsoft(minutes_won * 60 ) ; // Add any time won to user time,in minutes
// Let user check lines and then go to stats screen
print("\n\n\n Please Press A Key") ;
x := getch() ;
print_stats() ; // print out bets minutes won etc
log("TWon "+itostr(minutes_won)+" minutes" ); // Log any winnings
time_check(TRUE) ; //Start time checking again!
cls() ; // clear screen and return to MAX
return 0 ;
}